<html>
<head><meta charset="utf-8"><title>cx.tcx.is_promotable_const_fn is false for const fn · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cx.2Etcx.2Eis_promotable_const_fn.20is.20false.20for.20const.20fn.html">cx.tcx.is_promotable_const_fn is false for const fn</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="199701201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cx.tcx.is_promotable_const_fn%20is%20false%20for%20const%20fn/near/199701201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cx.2Etcx.2Eis_promotable_const_fn.20is.20false.20for.20const.20fn.html#199701201">(Jun 04 2020 at 03:15)</a>:</h4>
<p>For example this snippet:</p>
<div class="codehilite"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">skip_const_fn</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">const</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="n">v</span>: <span class="kt">i32</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Option</span><span class="o">&lt;</span><span class="kt">i32</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="nb">Some</span><span class="p">(</span><span class="n">v</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">None</span><span class="p">.</span><span class="n">or</span><span class="p">(</span><span class="n">foo</span><span class="p">(</span><span class="mi">42</span><span class="p">));</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">opt</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">opt</span><span class="p">.</span><span class="n">or</span><span class="p">(</span><span class="nb">Some</span><span class="p">(</span><span class="mi">2</span><span class="p">));</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>


<p><code>cx.tcx.is_promotable_const_fn</code> is false for <code>foo</code>.<br>
The <a href="https://github.com/rust-lang/rust/blob/b85e3fe010413b8c528d4de593d912a5ba024653/src/librustc_middle/query/mod.rs#L331-L338">documentation</a></p>



<a name="199702892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cx.tcx.is_promotable_const_fn%20is%20false%20for%20const%20fn/near/199702892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lzutao <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cx.2Etcx.2Eis_promotable_const_fn.20is.20false.20for.20const.20fn.html#199702892">(Jun 04 2020 at 03:59)</a>:</h4>
<p>Now I am using <code>rustc_mir::const_eval::is_const_fn</code></p>



<a name="199712579"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/cx.tcx.is_promotable_const_fn%20is%20false%20for%20const%20fn/near/199712579" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/cx.2Etcx.2Eis_promotable_const_fn.20is.20false.20for.20const.20fn.html#199712579">(Jun 04 2020 at 07:20)</a>:</h4>
<p><code>is_promotable_const_fn</code> is an internal hack used for a specific purpose. It's related to the <code>#[rustc_promotable]</code> attribute and both should not be used lightly</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>